var defaultParameter = {
  pageNumber: 1,
  pageSize: 20
};

var fileInfo ={
  uploadName:null,
  fileSuffix:null,
  uploadSize:null,
  filePath:null,
  uploadDt:null,
}

var tmpfiles;//文件上传下载

var showType="add";

var file = new com.im.common.file();
tmpfiles = file.activate(1);
$('#common_file').val('');
$('#common_file_name').hide();

var client = new com.im.common.ajax();

var filterParam={

};

function initTable(){

  var columns=[[
    {
        field : 'ck',
        checkbox : true
    },
    {field:'impleProjId',title:'项目id',fitColumns:true,hidden:true,
    },
    {field:'impleProjName',title:'实施项目名称',width:100,resizable:true,align:'left',fitColumns:true,
    },
    {field:'projStateName',title:'阶段',width:40,resizable:true,align:'left',fitColumns:true,
        formatter: function(value,row,index){
            if(row.projectStage!=null){
                return row.projectStage.projStateName;
            }else{
                return "";
            }
        }
    },
//    {field:'stageNode',title:'工作节点', width:$(this).width()*0.1,fitColumns:true,
//      formatter: function(value,row,index){
//      return row.stageNode.nodeName;
//      }
//    },
    {field:'uploadName',title:"文件名称",width:100,resizable:true,align:'left',fitColumns:true,
     formatter: function(value,row,index){
       if(row.docInfo!=null){
              return row.docInfo.fileName;
       }else{
         return "";
       }
     }
    },
      {field:'fileAttr',title:'文档属性',width:40,resizable:true,align:'center',fitColumns:true,
          formatter: function(value,row,index){
              if(row.uploadInfos!=null && row.uploadInfos.length>0) {
                  return row.uploadInfos[0].fileAttrName;
              }else{
                  return "";
              }
          }
      },
      {field:'fileType',title:'文档类型',width:40,resizable:true,align:'center',fitColumns:true,
          formatter: function(value,row,index){
              if( row.uploadInfos!=null && row.uploadInfos.length>0) {
                  return row.uploadInfos[0].fileTypeName;
              }else{
                  return "";
              }
          }
      },
      {field:'fileList',title:"文档列表",width:150,resizable:true,align:'left',fitColumns:true,
          formatter: function(value,row,index){
                  if(row.uploadInfos!=null && row.uploadInfos.length>0){
                     var html="";
                     for(var i=0;i<row.uploadInfos.length;i++){
                       html+="<span style='cursor:pointer'><u><a onclick='downloadFile(\""+row.uploadInfos[i].filePath+"\",\""+row.uploadInfos[i].uploadName+"\")'>"+row.uploadInfos[i].uploadName+"</a></u></span><br>";
                     }
                      return html;
                  }else{
                      return "";
                  }
          }
      },
      {field:'endDt',title:'完成时间', width:50,resizable:true,align:'left',fitColumns:true,
          formatter: function(value,row,index){
              if(row.docInfo!=null){
                  return row.docInfo.endDt;
              }else{
                  return "";
              }
          }
      },
//    {field:'filePath',title:"文件路径",width:$(this).width()*0.1,fitColumns:true,
//      formatter: function(value,row,index){
//        if(row.uploadInfo!=null) {
//          return row.uploadInfo.filePath;
//        }else{
//          return "";
//        }
//      }
//    },


    {field:'statusCdName',title:'状态',width:30,resizable:true,align:'center',fitColumns:true,
        formatter: function(value,row,index) {
            if(row.docInfo!=null) {
                return row.docInfo.statusCdName;
            }else{
                return "";
            }
        }
    },
    {field:'participant',title:'参与人',width:30,resizable:true,align:'center',fitColumns:true,
      formatter: function(value,row,index) {
      if(row.docInfo!=null) {
        return row.docInfo.participantName;
      }else{
        return "";
      }
      }
    },
    {field:'broker',title:"经手人",width:30,resizable:true,align:'center',fitColumns:true,
      formatter: function(value,row,index) {
        if(row.docInfo!=null) {
        return row.docInfo.brokerName;
        }else{
          return "";
        }
      }
    },
    {field:'description',title:"备注",width:80,resizable:true,align:'center',fitColumns:true,
      formatter: function(value,row,index) {
        if(row.docInfo!=null) {
          return row.docInfo.description;
        }else{
          return "";
        }
      }
    },
    {field:'operation',title:"操作",width:30,resizable:true,align:'center',
      formatter: function(value,row,index) {
          // if(row.level=="2"){
          //         return '<a class="edit" href="javascript:void(0)" title="编辑" onclick="updateFloderModel(\''
          //             + row.id
          //             + '\')"> <i class="fa fa-plus-square"></i></a>'
          //             // +
          //             //     '<a class="download" href="javascript:void(0)" title="增加节点" onclick="showAddModel(\''
          //             // + row.id
          //             // + '\')"><i class="fa  fa-plus-square font-middle"></i></a>'
          //            +
          //             '<a class="remove" href="javascript:void(0)" title="删除" onclick="delDoc(\''
          //             + row.id
          //             + '\')"><i class="fa fa-trash"></i></a>';
          // }else
          //     if(row.level=="3"){
          if ((row.docInfo != null) && (row.docInfo.statusCd == "10")) {
              return "";
          } else {
              return '<a class="edit" href="javascript:void(0)" title="编辑" onclick="updateFloderModel(\''
                  + index
                  + '\')"> <i class="fa fa-edit"></i></a>'
                  +
                  '<a class="remove" href="javascript:void(0)" title="删除" onclick="delDoc(\''
                  + index
                  + '\')"><i class="fa fa-trash"></i></a>';
          }
      // }
      // else{
      //     return "";
      // }

      }},
  ]];



  $('#fileInfoList').datagrid({
    url:'/InfoManageWeb/folderManageService/queryProjectStageDocInfo',
    method:'post',
    dataType : 'json',
    contentType: 'application/json',
    // idField:'id',
    // treeField:'projStageClass',
    queryParams:defaultParameter,
    nowrap:false,
    fitColumns:true,
    pagination:true,
    columns:columns,
    onBeforeLoad : function( param){
       for (var key in param) {
         if(key=="rows"){
           delete param[key];
         }
       }
     },
    loadFilter:function(data){
      console.log(data);
      if(data.resultCode!=0){
        toastr.error(data.resultCode);
        return null;
      }else{
        return data.result;
      }
    },
    //
    // onBeforeExpand : function(row) {
    //   // 此处就是异步加载地所在
    //   if (row) {
    //   if(row.level=="1"){
    //       filterParam.impleProjId=row.impleProjId;
    //       filterParam.parentId=row.id;
    //       $(this).treegrid('options').queryParams=filterParam;
    //       $(this).treegrid('options').url = '/InfoManageWeb/folderManageService/queryProjectStageForDocInfo'
    //   }
    //    if(row.level=="2"){
    //           filterParam.parentId=row.id;
    //           filterParam.projStageId=row.projStageId;
    //           $(this).treegrid('options').queryParams=filterParam;
    //           $(this).treegrid('options').url = '/InfoManageWeb/folderManageService/queryDocInfoByProjStageId'
    //       }
    //   }
    //   return true;
    // },
    onLoadSuccess:function(data){
        mergeCellsByField('fileInfoList','impleProjName',"projStateName");
    }

  });
  var p = $('#fileInfoList').datagrid('getPager');
  $(p).pagination({
    pageSize: 20,//每页显示的记录条数，默认为10
    pageList: [10,20,30],//可以设置每页记录条数的列表
    beforePageText: '第',//页数文本框前显示的汉字
    afterPageText: '页    共 {pages}  页',
    displayMsg: '当前显示 {from} - {to} 条记录 共 {total}  条记录',
    onSelectPage:function(pageNumber, pageSize){
      defaultParameter.pageNumber=pageNumber;
      defaultParameter.pageSize=pageSize;
        defaultParameter.projStageId=$('#projectStage').val();
        defaultParameter.impleProjId=$('#belongPlan').val();
        defaultParameter.planProjClass=$('#planProjClass').val();
        defaultParameter.orgId=$('#orgId').val();
  // $('#fileInfoList').treegrid('options').url="/InfoManageWeb/folderManageService/queryImplementProjectForDocInfo";
   $('#fileInfoList').datagrid('reload',defaultParameter);
    }
  });
}

function downloadFile(path,realName){
  location.href="/FileManageWeb/fileController/downloadFile?fileName="+path+"&realName="+encodeURI(encodeURI(realName));
}

function updateFloderModel(index){
    showType="update";
 $('#addEditModal').modal("show").find('.modal-title').html('文档编辑');
    var row= $('#fileInfoList').datagrid('getData').rows[index];

 // if(row.level=="2"){
 //     var parentNode=$('#fileInfoList').treegrid('find',row._parentId);
 //     if(row.projStageId!=null && row.projStageId!=""){
 //         $("#projStageId").val(row.projStageId);
 //     }else{
 //         $("#impleProjId").val(parentNode.impleProjId);
 //         $("#projStageClass").val(row.paramValValue);
 //     }
 // }else{
     $("#projStageId").val(row.projectStage.projStageId);
 // }
 $("#implProjectName").val(row.impleProjId).trigger("change");
 $("#projStageName").val(row.projectStage.projStageClass).trigger("change");
 if(row.uploadInfo!=null){
   $("#uploadId").val(row.uploadInfo.uploadId);
   $("#fileAttr").val(row.uploadInfo.fileType);
   file.activate(1,row.uploadInfo);
 }
 if(row.docInfo!=null){
   $("#endDt").val(row.docInfo.endDt);
   $("#fileName").val(row.docInfo.fileName);
   $("#participant").val(row.docInfo.participantName);
   $("#participantId").val(row.docInfo.participant);
   $("#docInfoId").val(row.docInfo.docInfoId);
   $("#broker").val(row.docInfo.brokerName);
   $("#brokerId").val(row.docInfo.broker);
 }
 disabledField(true);

}

function disabledField(flag){
    $("#planProjClassAdd").prop("disabled", flag);
    $("#orgIdAdd").prop("disabled", flag);
    $("#implProjectName").prop("disabled", flag);
    $("#projStageName").prop("disabled", flag);
}


/**
 * 保存文档信息
 */
function saveFolderInfo(){
  var docInfoId=$("#docInfoId").val();
  var param = {};
  var url="/folderManageService/updateDocInfo";
  if(docInfoId==null || docInfoId=="" || docInfoId==undefined){
    url="/folderManageService/addDocInfo";
  }else{
    param.docInfoId=$("#docInfoId").val();
  }

  param.projStageId=$("#projStageId").val();
  param.fileName=$("#fileName").val();
  param.endDt=$("#endDt").val();
  param.participant=$("#participantId").val();
  param.broker=$("#brokerId").val();
  param.description=$("#description").val();
  param.uploadId=$("#uploadId").val();
  param.fileAttr=$("#fileAttr").val();
  param.fileType=$("#fileType").val();
  param.impleProjId=$("#implProjectName").val();
  param.projStageClass=$("#projStageName").val();
  // param.uploadName=fileInfo.uploadName;
  // param.fileSuffix=fileInfo.fileSuffix;
  // param.uploadSize=fileInfo.uploadSize;
  // param.filePath=fileInfo.filePath;
  // param.uploadDt=fileInfo.uploadDt;
  var formValidator = $('#folderForm').data('bootstrapValidator');
  formValidator.options.excluded = [ ':hidden', ':not(:visible)'];
  formValidator.validate();
  if (formValidator.isValid()) {
    var fileList = [];
    var client = new com.im.common.ajax();
    //上传文件
    var filename = $('#common_file_name label');
    var files = [];
    var delFiles = [];
    for (var i = 0; i < filename.length; i++) {
      if (filename.eq(i).is(':visible')) {
        files.push(filename.eq(i).html());
      }
    }
    if(tmpfiles.del!=null && tmpfiles.del.length>0){
       delFiles=tmpfiles.del;
    }
    param.delFiles=delFiles;
    if (files.length > 0) {

      client.callAsFile(tmpfiles.newly, function (result) {
        if (!result.success) {
          toastr.error('文件上传失败！');
          return false;
        } else {
          $.each(result.result, function (index, item) {
            fileList.push(item);
          });
          param.fileList = fileList;
          var result = client.callAsJson(url, param);
          if (result.resultCode != 0) {
            toastr.error(result.resultCode);
          } else {
            $('#addEditModal').modal('hide');
            queryFolderInfo();
          }
        }
      });
    }else{
      var result = client.callAsJson(url, param);
      if (result.resultCode != 0) {
        toastr.error(result.resultCode);
      } else {
        $('#addEditModal').modal('hide');
        queryFolderInfo();
      }
    }

  }

}

function delDoc(index){
   var param={};
    var row= $('#fileInfoList').datagrid('getData').rows[index];
  param.docInfoId=row.docInfo.docInfoId;
  var client = new com.im.common.ajax();
  var result = client.callAsJson("/folderManageService/deleteDocInfo",param);
  if(result.resultCode!=0){
    toastr.error(result.resultCode);
  }else{
    queryFolderInfo();
  }
}

function showAddModel(id){
     $("#childAddModal").modal("show");
      var row=$('#fileInfoList').treegrid('find',id);
     $("#stageNodeId").val(row.stageNode.nodeId);
     $("#stageNodeName").val(row.stageNode.nodeName);
     $("#projStageId").val(row.projectStage.projStageId);
}

function queryFolderInfo(){
  defaultParameter.projStageId=$('#projectStage').val();
  defaultParameter.impleProjId=$('#belongPlan').val();
  defaultParameter.planProjClass=$('#planProjClass').val();
  defaultParameter.orgId=$('#orgId').val();
  // $('#fileInfoList').treegrid('options').url="/InfoManageWeb/folderManageService/queryImplementProjectForDocInfo";
  $('#fileInfoList').datagrid('load',defaultParameter);
}

function _callBackParticipant(staffId,staffName){
  $('#participantId').val(staffId);
}
function _callBackBroker(staffId,staffName){
  $('#brokerId').val(staffId);
}

function uploadFile(){
  // var formData = new FormData();
  var formData = new FormData($('#folderForm')[0]);
  // formData.append('file', $('#myFile')[0].files[0]);
  $.ajax({
    url: '/FileManageWeb/fileController/batchUploadFiles',
    type: 'POST',
    cache: false,
    data: formData,
    contentType : false,
    processData: false,
    success : function(data) {
      var result = JSON.parse(data);
      var info=result.result[0];
      fileInfo.uploadName=info.attachFullName;
      fileInfo.fileSuffix=info.attachSuffix;
      fileInfo.uploadSize=info.attachSize;
      fileInfo.filePath=info.attachPath;
      fileInfo.uploadDt=info.uploadDt;
      if (result.resultCode == '0') {
        result.success = true;
      } else {
        result.success = false;
      }
    },
  });
}


function initFileType(){
  var fileTypeList = client.callAsJson("commonService/queryTabColParam", {tabName:'T_FILE_UPLOAD',colName:'FILE_TYPE'}).result;
  fileTypeList.unshift({'colVal':'','colValName':'全部'});
  $.each(fileTypeList, function (i) {
      if(fileTypeList[i].colVal=="20"){
          $('#fileType').append("<option value=" + fileTypeList[i].colVal + " selected>" +fileTypeList[i].colValName + "</option>");
      }else{
          $('#fileType').append("<option value=" + fileTypeList[i].colVal + ">" +fileTypeList[i].colValName + "</option>");
      }


  });
  $("#fileType").select2({});
}

function initFileAttr(){
    var fileAttrList = client.callAsJson("commonService/queryTabColParam", {tabName:'T_FILE_UPLOAD',colName:'FILE_ATTR'}).result;
    fileAttrList.unshift({'colVal':'','colValName':'全部'});
    $.each(fileAttrList, function (i) {
        if(fileAttrList[i].colVal=="20"){
            $('#fileAttr').append("<option value=" + fileAttrList[i].colVal + " selected>" +fileAttrList[i].colValName + "</option>");
        }else{
            $('#fileAttr').append("<option value=" + fileAttrList[i].colVal + ">" +fileAttrList[i].colValName + "</option>");
        }


    });
    $("#fileAttr").select2({});
}

function saveNode(){
  var param={

  };
  param.projStageId=  $("#projStageId").val();
  param.nodeId=  $("#stageNodeId").val();
  param.nodeName=$("#childNodeName").val();
  if(param.nodeName==null || param.nodeName==undefined || param.nodeName.trim()==''){
    toastr.error("请输入节点名称");
    return;
  }
  var client = new com.im.common.ajax();
  var result = client.callAsJson("/folderManageService/insertChildNodeInfo",param);
  if(result.resultCode!=0){
    toastr.error(result.resultCode);
  }else{
    $('#childAddModal').modal('hide');
    queryFolderInfo();
  }

}

function clearFileInfo(){
  fileInfo.fileSuffix=null;
  fileInfo.uploadName=null;
  fileInfo.filePath=null;
  fileInfo.uploadSize=null;
}

function callBackItemProject(projectId,proejctName){
 $("#itemId").val(projectId);
}

function callBackProjectCondition(planProjectId,planProjectName){
 $("#planProjectId").val(planProjectId);
}
function _choseFile(type){
  var filename = $('#common_file_name label');
  for(var i = 0;i<filename.length;i++){
    if(filename.eq(i).is(':visible')){
      filename.eq(i).hide();
      $('#common_file_name a').eq(i).hide();
      $('#common_file_name br').eq(i).hide();
    }else{
      filename.eq(i).show();
      $('#common_file_name a').eq(i).show();
      $('#common_file_name br').eq(i).show();
    }

  }
}


function initBroker(){
    $("#broker").val(com.im.common.staffName);
    $("#brokerId").val(com.im.common.staffId);
}

function formValidator(){
    $("#folderForm").bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-loadData'
        },
        excluded: [':hidden', ':not(:visible)'],
        fields: {
            fileName: {
                trigger:"change",
                validators: {
                    notEmpty: {
                        message: '文件名称不能为空'
                    }
                }
            },
            fileType: {
                validators: {
                    notEmpty: {
                        message: '请选择文档类型'
                    }
                }
            },
            endDt: {
                trigger:"change",
                validators: {
                    notEmpty: {
                        message: '请选择完成时间'
                    }
                }
            },
            // participant: {
            //     trigger:"change",
            //     validators: {
            //         notEmpty: {
            //             message: '主要参与人不能为空'
            //         }
            //     }
            // },
            // broker:{
            //     trigger:"change",
            //     validators: {
            //         notEmpty: {
            //             message: '请选择经手人'
            //         }
            //     }
            // },
            statusCd: {
                validators: {
                    notEmpty: {
                        message: '请选择状态'
                    }
                }
            },
        }
    });
}

function mergeCellsByField(tableID, fldList,other) {
    var Arr = fldList.split(",");
    var dg = $('#' + tableID);
    var fldName;
    var RowCount = dg.datagrid("getRows").length;
    var span;
    var PerValue = "";
    var CurValue = "";
    var length = Arr.length - 1;
    for (i = length; i >= 0; i--) {
        fldName = Arr[i];
        PerValue = "";
        span = 1;
        for (row = 0; row <= RowCount; row++) {
            if (row == RowCount) {
                CurValue = "";
            }
            else {
                    CurValue = dg.datagrid("getRows")[row][fldName];
            }
            if (PerValue === CurValue) {
                span += 1;
            }
            else {
                var index = row - span;
                dg.datagrid('mergeCells', {
                    index: index,
                    field: fldName,
                    rowspan: span,
                    colspan: null
                });
                var name = other.split(",");
                $.each(name,function (i,item){
                    dg.datagrid('mergeCells', {
                        index: index,
                        field: item,
                        rowspan: span,
                        colspan: null
                    });
                });
                span = 1;
                PerValue = CurValue;
            }
        }
    }
}

function approvalFiles(){
    var rows=$('#fileInfoList').datagrid('getChecked');
    if(rows.length<1){
        toastr.info('请至少选中一行');
        return;
    }
    var docInfoIds="";
    for(var i=0;i<rows.length;i++){
        if(i==rows.length-1){
            docInfoIds+=rows[i].docInfo.docInfoId;
        }else{
            docInfoIds+=rows[i].docInfo.docInfoId+",";
        }
    }
    var param={};
    param.docInfoIds=docInfoIds;
    var client = new com.im.common.ajax();
    var result = client.callAsJson("folderManageService/updateBatchDcoInfoForAudit",param);
    if(result.resultCode!=0){
        toastr.error(result.resultCode);
    }else{
        queryFolderInfo();
    }
}

$(function() {
    var param ={};
    param.limitTypeId ="60";
    param.chkType ="2";
    param.rangeValue = '10011001';
    var staffLimitRst= com.im.staffLimitCommpent.invoke.staffLimitJudge(param);

    if (staffLimitRst != false ) {
        if (!staffLimitRst.result.ret) {
            $("#approvalBtn").hide();
        } else {
            ;
        }
    }

    $("#orgId").project2unit2itemCommpent({
        //elmIdProjectSel : "projectSel",//规划工程下拉元素
        elmIdPlanTypeSel : "planProjClass",
        elmIdUnitSel : "orgId",//组织单位下拉元素
        elmIdItemSel : "belongPlan",//实施项目下拉元素
        orgType : "10",//初始化单位时，单位类型
        callbackFunc: function (callBackType, ret) {//下拉框值改变时回调
            //_callBackOrg(objvalue, objname);
            //callBackType : 1 所属规划值变更 2单位值变更  3项目名称变更
            //ret: orgId,orgName,impleProjId,impleProjName,planProjClass,planProjClassName
            queryFolderInfo();
        }
    });


    //增加窗口的方法
    $("#orgIdAdd").project2unit2itemCommpent({
        //elmIdProjectSel : "projectSel",//规划工程下拉元素
        elmIdPlanTypeSel : "planProjClassAdd",
        elmIdUnitSel : "orgIdAdd",//组织单位下拉元素
        elmIdItemSel : "implProjectName",//实施项目下拉元素
        orgType : "10",//初始化单位时，单位类型
        callbackFunc: function (callBackType, ret) {//下拉框值改变时回调

        }
    });

  initTable();

  initFileAttr();

  initFileType();

  initBroker();

  $("#userBtn").click(function() {
    $("#participant").userSearchCommpent({
      elmIdOut : "participant",//组织树单击之后回填的文本框（input）
      elmIdModal : "userSearchModal",//用户选择
      elmIdOrgModal : "unitSearchModal",//组织查询
      callbackFunc: function (staffId, staffName) {//组织树单击之后回调函数
        _callBackParticipant(staffId, staffName);
      }
    });
  });

  $("#userBtn1").click(function() {
    $("#broker").userSearchCommpent({
      elmIdOut : "broker",//组织树单击之后回填的文本框（input）
      elmIdModal : "userSearchModal",//用户选择
      elmIdOrgModal : "unitSearchModal",//组织查询
      callbackFunc: function (staffId, staffName) {//组织树单击之后回调函数
        _callBackBroker(staffId, staffName);
      }
    });
  });


  $("#ensureBtn").click(function(){
    saveFolderInfo();
  });

    $('#addEditModal').on('shown.bs.modal', function () {
       if(showType=='add'){
           var planProjClass=$("#planProjClass").val();
           var orgId=$("#orgId").val();
           var projId=$("#belongPlan").val();
           $("#planProjClassAdd").val(planProjClass).trigger("change");
           $("#orgIdAdd").val(orgId).trigger("change");
           $("#implProjectName").val(projId).trigger("change");
       }
    });

  $('#addEditModal').on('hidden.bs.modal', function () {
    $("#impleProjId").val("");
    $("#projStageClass").val("");
    $("#projStageId").val("");
    $("implProjectName").val("").trigger("change");
    $("#planProjClassAdd").val("").trigger("change");
    $("#orgIdAdd").val("").trigger("change");
    $("#projStageName").val("").trigger("change");
    $("fileName").val("").trigger("change");
    $("fileAttr").val("").trigger("change");
    $("fileType").val("").trigger("change");
    $("#participant").val("").trigger("change");
    $("#participantId").val("").trigger("change");
    $("#broker").val("").trigger("change");
    $("#brokerId").val("").trigger("change");
    tmpfiles = file.activate(1);
      $('#common_file').val('');
      $('#common_file_name').hide();
    $("#nodeId").val("");
    $("#docInfoId").val("");
    $("#uploadId").val("");
    $("#fileName").val("").trigger("change");
    $("#endDt").val("").trigger("change");
    $("#participant").val("").trigger("change");
    $("#brokerId").val("").trigger("change");
    $("#folderForm").data('bootstrapValidator').destroy();
    $('#folderForm').data('bootstrapValidator', null);
    formValidator();
     initBroker();
    clearFileInfo();
  });

  $('.datetimepicker').datepicker({
      onSelect:function (){
      	$('.datetimepicker').trigger("change");
      }
  });

  // $("#planProjClass").constantCommpent({
  //   elmIdSel : "planProjClass",//需要展示的位置下拉框
  //   constParamCode : "PLAN_PROJ_CLASS",//需要加载的常量编码
  //   callbackFunc: function (objvalue, objname) {//下拉框值改变时回调
  //   }
  // });

  $("#projectStage").constantCommpent({
    elmIdSel : "projectStage",//需要展示的位置下拉框
    constParamCode : "PROJECT_STAGE",//需要加载的常量编码
    callbackFunc: function (objvalue, objname) {//下拉框值改变时回调
    }
  });

    $("#projStageName").constantCommpent({
        elmIdSel : "projStageName",//需要展示的位置下拉框
        constParamCode : "PROJECT_STAGE",//需要加载的常量编码
        callbackFunc: function (objvalue, objname) {//下拉框值改变时回调
        }
    });


    // $("#itemBtn").click(function() {
    //         $("#itemBtn").itemSearchCommpent({
    //             elmIdOut : "itemOut",//组织树单击之后回填的文本框（input）
    //             elmIdModal : "itemSearchModal",//用户选择
    //             elmIdOrgModal : "unitSearchModal3",//组织查询
    //             callbackFunc: function (projectId, projectName) {//组织树单击之后回调函数
    //                 callBackItemProject(projectId, projectName);
    //             }
    //         });
    // });

  // $("#projectBtn").click(function() {
  //   $("#projectBtn").projectSearchCommpent({
  //     elmIdOut : "projectOut",//组织树单击之后回填的文本框（input）
  //     elmIdModal : "projectSearchModal",//用户选择
  //     elmIdOrgModal : "unitSearchModal",//组织查询
  //     callbackFunc: function (projectId, projectName) {//组织树单击之后回调函数
  //        callBackProjectCondition(projectId, projectName);
  //     }
  //   });
  // });

  $('#myFile').change(function (){
          	var reg = /[^\\\/]*[\\\/]+/g;
   $('#myFileName').val($(this).val().replace(reg, ''));
  });


  $("#queryBtn").click(function(){
    queryFolderInfo();
  });

  $("#fileBtn").click(function(){
    uploadFile();
  });

  $("#approvalBtn").click(function(){
     approvalFiles();
  });

  $("#saveNodeBtn").click(function(){
     saveNode();
  });

  $("#btn_add").click(function(){
      showType="add";
      $("#addEditModal").modal("show");
      disabledField(false);
  });

    _choseFile($(this).attr('id'))




//    $(".datetimepicker").daterangepicker({
//          singleDatePicker: true,
//          showDropdowns: true,
//          drops:'right',
//          locale: {
//            format: 'YYYY-MM-DD HH:mm:ss',
//            daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
//            monthNames: ['一月', '二月','三月', '三月', '四月', '五月','六月', '七月', '八月','九月','十月','十一月','十二月'],
//          },
//          timePicker: true,
//          timePicker24Hour: true,
//          format: 'YYYY-MM-DD HH:mm:ss',
//          timePickerIncrement: 1,
//          minDate:moment('2017-01-01 00:00:00'),
//        },
//        function (start, end, label) {
//        }
//    );
    formValidator();

});